﻿<?php
session_start();

//Listas de Datos
$articulo_mostrar 	= $_SESSION['articulo_mostrar'];
$id_articulo 		= $articulo_mostrar[0][0].$articulo_mostrar[0][1].$articulo_mostrar[0][2];

include('../ayuda/class.ezpdf.php');

$pdf =& new Cezpdf('LETTER','portrait');
$pdf->selectFont('../../publicos/fonts/Helvetica.afm');

$pdf->addJpegFromFile('../../publicos/imagenes/pagina/tira_logo.jpg',100,735,390,20);

$pdf->addText(25,695,10,utf8_decode("<b>Fecha y Hora de Emisión: </b>".date("d/m/Y - H:i:s")));
$pdf->addText(25,683,10,utf8_decode("<b>Usuario: </b>José Calvo"));

$pdf->line(25,652,575,652);
$pdf->setLineStyle(1);
$pdf->addText(150,638,10,utf8_decode('<b>DATOS BASICOS</b>'));

$pdf->line(25,630,575,630);
$pdf->setLineStyle(1);

$i = 0;
$y = 608;
$pie = 1;

$pdf->addText(30,$y,10,utf8_decode("<b>ID ARTÍCULO: </b>"));
$pdf->addText(190,$y,10,"<b>".$id_articulo."</b>");		
$y = $y - 14;
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Tipo de Artículo: "));
$pdf->addText(190,$y,10,$articulo_mostrar[0][1]." - ".$articulo_mostrar[0][7]);
$y = $y - 14;
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Subtipo de Artículo: "));
$pdf->addText(190,$y,10,$articulo_mostrar[0][2]." - ".$articulo_mostrar[0][8]);
$y = $y - 14;
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Nombre: "));
$pdf->addText(190,$y,10,$articulo_mostrar[0][3]);
$y = $y - 14;
$y = $y - 14;

$ancho = 65;
$pdf->addText(30,$y,10,utf8_decode("Descripción: "));

$z = 0;
$texto = split(", ", $articulo_mostrar[0][4]);

while ( $z < count($texto) ) {
	$pdf->addText(190,$y,10,$texto[$z]);
	$y = $y - 14;
	$z++;
}






/*// Valores Iniciales
$inicio 	= 0;
$index = 0;
$text 		= $articulo_mostrar[0][4];
$long_text 	= strlen($text);	
	
for ( $j = 0; $j < $long_text; $j++ ) {
		
	if ( $text[$j] == " ") {
		$index = $j;
	}
	
	if ( $j == $ancho ) {
		$text_turno = substr($text, $inicio, $index);					
		if ( $text_turno[strlen($text_turno)] == " ") {
			$text_turno = substr($text, $inicio, $index-1);
		}
				
		$pdf->addTextWrap(190,$y,440,10,$text_turno,$justification='full',$angle=0,$test=0);					
		$y = $y - 14;
		$text = substr($text, $index+1, strlen($text));
		
		$j = 0;
		$long_text 	= strlen($text);
	}
	
	if ( $j == $long_text-1 ) {
		$pdf->addTextWrap(190,$y,440,10,$text,$justification='full',$angle=0,$test=0);
		$y = $y - 14;
	}
}*/
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Medidas: "));
$pdf->addText(190,$y,10,$articulo_mostrar[0][5]);
$y = $y - 14;
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Precio: "));
$pdf->addText(190,$y,10,$articulo_mostrar[0][6]." BsF.");
$y = $y - 14;
$y = $y - 14;
$pdf->addText(30,$y,10,utf8_decode("Fecha de Modificación: "));
$pdf->addText(190,$y,10,$_SESSION['fecha_variable_precio']);
$y = $y - 14;
$y = $y - 14;
	
$pdf->addText(550, 40, 8, "- ".$pie." -");



// SIGUIENTE PAGINA

$tipo_articulo = substr($id_articulo, 0, 2);

$pdf->ezNewPage();
$pie ++;

$pdf->addJpegFromFile('../../publicos/imagenes/pagina/tira_logo.jpg',100,735,390,20);

$pdf->addText(25,695,10,utf8_decode("<b>Fecha y Hora de Emisión: </b>".date("d/m/Y - H:i:s")));
$pdf->addText(25,683,10,utf8_decode("<b>Usuario: </b>José Calvo"));

$pdf->line(25,652,575,652);
$pdf->setLineStyle(1);
$pdf->addText(150,638,10,utf8_decode('<b>MEDIDAS</b>'));					
$pdf->line(25,630,575,630);
$pdf->setLineStyle(1);

switch ( $tipo_articulo ) {		
		
	case "01":	$x_image = 150;
				$y_image = 350;
				break;
						
	case "02":	$x_image = 100;
				$y_image = 50;
				break;
				
	case "03":	$x_image = 100;
				$y_image = 50;
				break;
	
	case "04":	$x_image = 90;
				$y_image = 30;
				
				// PARA LOS DIBUJO PEQUEÑOS
				$subtipo_articulo = substr($id_articulo, 2, 2);
				
				if ( $subtipo_articulo == "05" ) {
					$x_image = 60;
					if ( $id_articulo == "040505" || $id_articulo == "040506" ) {
						$x_image = 20;
					}
					$y_image = 300;
				}
				break;
	
	case "05":	$x_image = 60;
				$y_image = 200;
				break;
					
	case "06":	$subtipo_articulo = substr($id_articulo, 2, 2);
	
				if ( $subtipo_articulo == "01" ) {
					$x_image = 170;
					$y_image = 200;
				} else if ( $subtipo_articulo == "02" ) {
					$x_image = 140;
					$y_image = 200;
				} else if ( $subtipo_articulo == "03" || $subtipo_articulo == "04" ) {
					$x_image = 50;
					$y_image = 150;
				} else if ( $subtipo_articulo == "05" ) {
					$x_image = 50;
					$y_image = 450;
				}
				break;
	
	case "07":	$subtipo_articulo = substr($id_articulo, 2, 2);
	
				if ( $subtipo_articulo == "01" ) {
					$x_image = 60;
					$y_image = 200;
				} else if ( $subtipo_articulo == "02" ) {
					$x_image = 60;
					$y_image = 150;
				} else if ( $subtipo_articulo == "03" ) {
					$x_image = 60;
					$y_image = 70;
				}
				break;
	
	case "08":	$x_image = 90;
				$y_image = 250;
				break;
	
	case "09":	$subtipo_articulo = substr($id_articulo, 2, 2);
	
				if ( $subtipo_articulo == "01" ) {
					$x_image = 100;
					$y_image = 250;
				} else if ( $subtipo_articulo == "02" ) {
					$x_image = 120;
					$y_image = 450;
				} else if ( $subtipo_articulo == "03" || $subtipo_articulo == "04" || $subtipo_articulo == "06" || $subtipo_articulo == "07" ) {
					$x_image = 50;
					$y_image = 200;
				} else if ( $subtipo_articulo == "05" ) {
					$x_image = 50;
					$y_image = 40;
				}
				break;
	
	case 10:	$x_image = 90;
				$y_image = 90;
				break;
	
	case 11:	break;
	
	default: 	break;		
}

$pdf->addJpegFromFile('../../publicos/imagenes/articulos_medidas/'.$id_articulo.'.jpg',$x_image,$y_image);
$pdf->addText(550, 40, 8, "- ".$pie." -");

// SEGUNDA PAGINA
$pdf->ezNewPage();
$pie ++;

$pdf->addJpegFromFile('../../publicos/imagenes/pagina/tira_logo.jpg',100,735,390,20);

$pdf->addText(25,695,10,utf8_decode("<b>Fecha y Hora de Emisión: </b>".date("d/m/Y - H:i:s")));
$pdf->addText(25,683,10,utf8_decode("<b>Usuario: </b>José Calvo"));

$pdf->line(25,652,575,652);
$pdf->setLineStyle(1);
$pdf->addText(150,638,10,utf8_decode('<b>DESGLOCE</b>'));

$pdf->line(25,630,575,630);
$pdf->setLineStyle(1);

$pdf->addJpegFromFile('../../publicos/imagenes/articulos_desgloce/'.$id_articulo.'.jpg',70,50);

$pdf->addText(550, 40, 8, "- ".$pie." -");

if ( $id_articulo == "030112" )  {

	// SEGUNDA PAGINA
	$pdf->ezNewPage();
	$pie ++;
	
	$pdf->addJpegFromFile('../../publicos/imagenes/pagina/tira_logo.jpg',100,735,390,20);
	
	$pdf->addText(25,695,10,utf8_decode("<b>Fecha y Hora de Emisión: </b>".date("d/m/Y - H:i:s")));
	$pdf->addText(25,683,10,utf8_decode("<b>Usuario: </b>José Calvo"));
	
	$pdf->line(25,652,575,652);
	$pdf->setLineStyle(1);
	$pdf->addText(150,638,10,utf8_decode('<b>DESGLOCE</b>'));
	
	$pdf->line(25,630,575,630);
	$pdf->setLineStyle(1);
	
	$pdf->addJpegFromFile('../../publicos/imagenes/articulos_desgloce/'.$id_articulo.'_2.jpg',70,50);
	
	$pdf->addText(550, 40, 8, "- ".$pie." -");
}

$pdf->ezStream();
?>